<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ include file="/common/backcommon.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Breaking Fast</title>
		<script type="text/javascript">
			function deleteOperate(id) {
				if(confirm("是否删除该套餐？")) {
					$.ajax({
						url: "${base}/backComboCtl/delete",
						type: "post",
						data: {comboId : id},
						success: function(result){
							if(true == result) {
								alert("删除成功");
							}
						},
						error:function(){
							alert("删除失败");
						}
					});
					setTimeout("onPageChange(1)", 2000);
				}
			};
			
			function updateOperate(id) {
				location.href = "${base}/backComboCtl/toUpdate?comboId=" + id;
			};
			
			function detailOperate(id) {
				location.href = "${base}/backComboCtl/detail?comboId=" + id;
			};
			
	        function loadPage(totalCount, pageSize, pageCurrent) {
		        $("#page").smartpaginator({
                    totalrecords: totalCount, 
                    recordsperpage: pageSize, 
                    initval: pageCurrent,  
                    next: '下一页', 
                    prev: '上一页', 
                    first: '第一页', 
                    last: '最后一页', 
                    theme: 'black', 
                    go: 'Go',
                    onchange: onPageChange
				});
	        };
			
			function onPageChange(newPageValue) {
				//获取查询参数
				var comboChName = $("#comboChName").val();
				var comboEnName = $("#comboEnName").val();
				var priceMax = $("#priceMax").val();
				var priceMin = $("#priceMin").val();
				var startDate = $("#startDate").val();
				var endDate = $("#endDate").val();
				var params = {
					comboChName : comboChName,
					comboEnName : comboEnName,
					priceMax : priceMax,
					priceMin : priceMin,
					startDate : startDate,
					endDate : endDate,
					pageNumber : newPageValue
				};
				var dataTr = $("#pageList tr");
				for(var i = 0; i < dataTr.length; i++) {
					if(i != 0) {
						$(dataTr[i]).remove();
					}
				}
				$.ajax({
					url: "${base}/backComboCtl/select",
					type: "post",
					data: params,
					success: function(result){
						var dataTable = $("#pageList");
						for(var i = 0; i < result.resultList.length; i++) {
							var trClassName = ""; 
							if(i%2 == 0){
								trClassName = "list_tab_left";
							}
							var comboid = result.resultList[i].comboid;
							var combozhname = result.resultList[i].combochname;
							var comboenname = result.resultList[i].comboenname;
							var price = result.resultList[i].price;
							var hot = result.resultList[i].hot;
							var createdate = result.resultList[i].createdateStr;
							var username = result.resultList[i].createuser.username;
							var status = result.resultList[i].status;
							var row = "<tr class='" + trClassName + "'><td>" + combozhname + "</td><td>" + comboenname + "</td>" + 
								"<td>" + price + "</td><td>" + hot + "</td><td>" + createdate + "</td><td>" + username + "</td><td>";
							if(2 != status) {
								row += "<a href='#' onclick='deleteOperate(\"" + comboid + "\")'>删除</a>&nbsp;&nbsp;";
							}
							row = row + "<a href='#' onclick='updateOperate(\"" + comboid + "\")'>修改</a>&nbsp;&nbsp;" + 
								"<a href='#' onclick='detailOperate(\"" + comboid + "\")'>详情</a></td></tr>";
							dataTable.append($(row));
						}
						$("#pageList tr:even").addClass("bg_color");
						loadPage(result.totalCount, result.pageSize, result.pageCurrent);
					}
				});
			};
			
			$(function() {
				onPageChange(1);
				
				$("#queryBtn").bind("click",function(){
					if($.formValidator.pageIsValid("1")) {
						var pageNumber = $("#pageNumber").val();
						onPageChange(pageNumber);
					}
				});
				
				//验证信息
				$.formValidator.initConfig({
					formID: "queryForm",
					debug:false,
					onError: function(msg, obj, errorlist){
					}
				});
				$("#comboChName").formValidator({empty:true, onShow:"请输入中文套餐名", onCorrect:"恭喜你,你输对了"}).inputValidator({max:25, onError:"你输入的中文套餐名太长"}).regexValidator({regExp: "Illegal", dataType:"enum", onError:"中文套餐名中包含非法字符"});
				$("#comboEnName").formValidator({empty:true, onShow:"请输入英文套餐名", onCorrect:"恭喜你,你输对了"}).inputValidator({max:25, onError:"你输入的英文套餐名太长"}).regexValidator({regExp: "enname", dataType:"enum", onError:"英文套餐名中包含非法字符"});
				$("#priceMin").formValidator({empty:true, tipID:"priceMinTip", onShow: "请输入数字", onCorrect: "恭喜你,你输对了" }).inputValidator({min:0, max:9999, type:"value", onErrorMin:"你输入的值必须大于等于0", onError:"单价必须在0-9999之间，请确认"}).compareValidator({desEmpty:true, desID:"priceMax", dataType:"number", operateor:"<=", onError:"起始单价不能大于结束单价"}).defaultPassed();
				$("#priceMax").formValidator({empty:true, tipID:"priceMaxTip", onShow: "请输入数字", onCorrect: "恭喜你,你输对了" }).inputValidator({min:0, max:9999, type:"value", onErrorMin:"你输入的值必须大于等于0", onError:"单价必须在0-9999之间，请确认"}).compareValidator({desEmpty:true, desID:"priceMin", dataType:"number", operateor:">=", onError:"结束单价不能小于起始单价"}).defaultPassed();
			});
		</script>
	</head>
	
	<body>
		<div class="cms_right">
		  	<div class="cms_title">
		    	<span>套餐管理：</span>
		    </div>
			    <div class="cms_search">
	    			<form id="queryForm" >
						<table width="1000" border="0" class="search_bd">
							<tr>
					            <td class="yh_name">中文套餐名：</td>
					            <td class="yh_bd"><input type="text" id="comboChName" class="cms_text02" maxlength="25" /></td>
					            <td class="tishi"><div id="comboZhNameTip" style="width:200px"></div></td>
					            <td class="yh_name">英文套餐名：</td>
					            <td class="yh_bd"><input type="text" id="comboEnName" class="cms_text02" maxlength="25" /></td>
					            <td class="tishi"><div id="comboEnNameTip" style="width:200px"></div></td>
							</tr>
							<tr>
					            <td class="yh_name">起始单价：</td>
					            <td class="yh_bd"><input type="text" id="priceMin" class="cms_text02" /></td>
					            <td class="tishi"><div id="priceMinTip" style="width:200px"></div></td>
					            <td class="yh_name">结束单价：</td>
					            <td class="yh_bd"><input type="text" id="priceMax" class="cms_text02" /></td>
					            <td><div id="priceMaxTip" style="width:200px"></div></td>
							</tr>
							<tr>
								<td class="yh_name">开始时间：</td>
								<td class="yh_bd"><input type="text" id="startDate" class="Wdate" style="cursor: pointer" onFocus="WdatePicker({readOnly:true})" /></td>
								<td class="tishi"><div id="startDateTip" style="width:200px"></div></td>
								<td class="yh_name">结束时间：</td>
								<td class="yh_bd"><input type="text" id="endDate" class="Wdate" style="cursor: pointer" onFocus="WdatePicker({readOnly:true})" /></td>
								<td><div id="endDateTip" style="width:200px"></div></td>
							</tr>
							<tr>
								<td></td>
								<td align="right"><input type="reset" class="search_btn" value="重置" /></td>
								<td align="center" ><input type="button" id="queryBtn" class="search_btn" value="搜索" /></td>
								<td><input type="button" id="queryBtn" class="search_btn" value="新增" onclick="location.href='${base }/background/combo/comboadd.jsp'" /></td>
								<td></td>
								<td></td>
							</tr>
				        </table>
		   			</form>
			    </div>
			<div class="grid-view">
				<table id="pageList" class="items" width="100%" border="1" cellspacing="0" cellpadding="0">
					<tr class="list_tab_title">
						<td bgcolor="#eae9eb">中文套餐名</td>
						<td bgcolor="#eae9eb">英文套餐名</td>
						<td bgcolor="#eae9eb">单价</td>
						<td bgcolor="#eae9eb">热量(千卡)</td>
						<td bgcolor="#eae9eb">创建时间</td>
						<td bgcolor="#eae9eb">创建人</td>
						<td bgcolor="#eae9eb">操作</td>
					</tr>
				</table>
				<div id="page" style="margin: auto;"></div>
			</div>
		</div>
	</body>
</html>
	